import csv

def main():
    csvFile = 'pci.csv'
    #makeVendors(csvFile)
    #makeDevices(csvFile)
    makeUhci(csvFile)
    return

def makeDevices(csvFile):

    print """typedef struct pciDevice
{
    unsigned short vendorID;
    unsigned short deviceID;
    char *device;
}pciDevice;

pciDevice pciDevices[] =
{"""

    file = csv.reader(open(csvFile))
    cant = 0;
    for row in file:
        cant += 1
        print '    {' + row[0] + ', ' + row[1] + ', "' + row[3] + row[4] + '"},'


    print '};'
    print '\n#define pciDevLen ' + str(cant) + '\n'

    return

def makeVendors(csvFile):

    last = ''

    print """typedef struct pciVendor
{
    unsigned short vendorID;
    char *vendor;
}pciVendor;

pciVendor pciVendors[] =
{"""

    file = csv.reader(open(csvFile))
    cant = 0;
    for row in file:
        if last != row[0]:
            last = row[0]
            cant += 1
            print '    {' + row[0] + ', "' + row[2] + '"},'


    print '};'
    print '\n#define pciVenLen ' + str(cant) + '\n'

    return

def makeUhci(csvFile):

    print """typedef struct uhciDevice
{
    unsigned short vendorID;
    unsigned short deviceID;
    char *device;
}uhciDevice;

uhciDevice uhciDevices[] =
{"""

    file = csv.reader(open(csvFile))
    cant = 0;
    for row in file:
        if 'USB' in (row[4].upper() + row[3].upper()):
            if 'EHCI' not in (row[4].upper() + row[3].upper()):
                if 'OpenHCD' not in (row[4].upper() + row[3].upper()):
                    if 'ADAPTER' not in (row[4].upper() + row[3].upper()):
                        if 'OHCI' not in (row[4].upper() + row[3].upper()):
                            if 'OPEN' not in (row[4].upper() + row[3].upper()):
                                cant += 1
                                print '    {' + row[0] + ', ' + row[1] + ', "' + row[3] + row[4] + '"},'


    print '};'
    print '\n#define uhciDevLen sizeof(uhciDevices)/sizeof(uhciDevice)' + '\n'

    return

if __name__ == '__main__':
   main()